package com.fu.plugin.model;

import com.fu.plugin.navigation.MyNavigationItem;
import com.intellij.ide.util.gotoByName.FilteringGotoByModel;
import com.intellij.navigation.ChooseByNameContributor;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FilterModel extends FilteringGotoByModel {

    public FilterModel(@NotNull Project project, @NotNull ChooseByNameContributor[] contributors){
        super(project, contributors);
    }

    /***
     * @description: 命中选项
     * @param navigationItem
     * @return
     */
    @Nullable
    @Override
    protected Object filterValueFor(NavigationItem navigationItem) {
        if(navigationItem instanceof MyNavigationItem){
            MyNavigationItem myNavigationItem = (MyNavigationItem) navigationItem;
            return myNavigationItem.getDemo();
        }
        return null;
    }

    /**
     * 搜索框标题
     * @return
     */
    @Nls(capitalization = Nls.Capitalization.Sentence)
    @Override
    public String getPromptText() {
        return "Enter";
    }

    @NotNull
    @Override
    public String getNotInMessage() {
        return "Not in Message";
    }

    @NotNull
    @Override
    public String getNotFoundMessage() {
        return "Not found message";
    }

    /**
     * 过滤器是否打开
     * @return
     */
    @Nullable
    @Override
    public String getCheckBoxName() {
        return "New Check";
    }

    @Override
    public boolean loadInitialCheckBoxState() {
        return false;
    }

    @Override
    public void saveInitialCheckBoxState(boolean b) {

    }

    @NotNull
    @Override
    public String[] getSeparators() {
        return new String[]{"/", "?"};
    }

    /**
     * 必须重写，返回数据项
     * @param o
     * @return
     */
    @Nullable
    @Override
    public String getFullName(@NotNull Object element) {
        return ((MyNavigationItem)element).getValue();
    }

    @Override
    public boolean willOpenEditor() {
        return true;
    }
}